<#include "../common/_header.htm">
<div class="content-wrapper" style="margin-left: 0px">
	<section class="content">
		<div class="row">
			<div class="bill-right">
				<form id="listForm">
					<div class="box bg_gray">
						<div class="box-header">
							<div class="row RowSearchWork">
								<div class="col-sm-12">
									<div class="form-group">
										<div class="importti">
											<span class="importfont"><span class="sming"></span><span class="smtit">战法说明：该战法主要用于分析多个账户向同一账户同向转移资金、间隔时间比较固定、不同的交易日期反复出现的资金，通过该战法可发现团伙控制的账户。主要用于地下钱庄，反洗钱案件。</span></span>
										</div>
				                        <div class="form-inline">
				                            <div class="form-group">
				                                <label class="control-label">交易月份</label>
				                                <input type="text" class="form-control form_datetime" id="starTime" placeholder="" />
				                            </div>
				                            <div class="form-group">
				                                <label class="control-label refsh"> 至 </label>
				                                <input type="text" class="form-control form_datetime" id="endTime" placeholder="" />
				                            </div>
											<div class="form-group" id="sign-info">
												<label class="control-label hidden-xs"> 收付标志</label>
												<select class="zjzysign">
													<option value="0">收入</option>
													<option value="1">支出</option>
												</select>
											</div>
											<div class="form-group" >
												<label class="control-label hidden-xs"> 关键字</label>
												<input type="text" placeholder="对手卡号\对手户名" id="keyword"> <span style="font-size: 12px;color: #6f7689"></span>
											</div>
											<div class="form-group" id="hour">
												<label class="control-label hidden-xs"> 转移资金间隔时长</label>
												<input type="text" value="1" class="zjzytime"> <span style="font-size: 12px;color: #6f7689">小时</span>
											</div>
											<div class="form-group" id="tradeCount">
												<label class="control-label hidden-xs"> 不同交易日期总天数大于</label>
												<input type="text" value="3" class="zjzytime"> <span style="font-size: 13px;color: #6f7689">天</span>
											</div>
				                            <div class="form-group bill-buttonarea ml10" >
												<input type="button" class="btn btn-primary" onclick="_checkedCallback();" value="分析" />
												<input type="button" class="btn btn-default" onclick="reset();" value="重置" />
												<input type="button" class="btn btn-primary daobtn" onclick="exportList();" value="导出" />
											</div>
				                        </div>

			                        </div>
								</div>
							</div>
						</div>
						<div class="box-body">
							<div class="box-body table-responsive">
								<span id="spantitle" class="title"></span>
								<table id="dg"></table>
							</div>
						</div>
					</div>
				</form>
			</div>
		</div>
	</section>
</div>
<script type="text/javascript">
    function refreshSize(){
        var totolHeight =  document.documentElement.clientHeight;
        var height = totolHeight - 200
        console.log(totolHeight + ' - ' + height);
        document.getElementById('dg').style.height = height+'px';
    };
    refreshSize();
    window.onresize = refreshSize;
	var caseId=parent.caseId;
	 $(window).resize(function(){
		$('#dg').datagrid('resize',{
			height:($(window).height())-($('.box-header').outerHeight(true))-($('#spantitle').outerHeight(true))-35,
		});
	});
    $(".form_datetime").datepicker({
	    format: "yyyy-mm-dd",
	    autoclose: true,
	    language:'zh-CN',
	    pickerPosition:"bottom-left"
	});
    var spantitle = $("#spantitle");
    spantitle.html('<span><a class="listap" style="cursor:pointer;" onclick="_checkedCallback()">伴随资金转移</a></span>');

	function _checkedCallback() {
		let arr = parent.parent._checkedAccount;
		if (arr&&arr.length!=1){
			toastr.error("请选择一个交易主体卡号","提示信息");
			firstTable()
			return false;
		}else{
			let accountBodyCard=arr[0].split("_")[1];;
			firstTable(accountBodyCard)
		}
	}
    window.onload= _checkedCallback;
    function firstTable(accountBodyCard){
    	let starTime = $.trim($("#starTime").val());
        let endTime = $.trim($("#endTime").val());
		let sign=$("#sign-info option:selected").val();
		let tradeCount=$("#tradeCount input").val();
		let hour=$("#hour input").val();
		let keyword=$("#keyword").val();
		$('#dg').datagrid({
			method : 'post', // 服务器数据的请求方式 get or post
			url:"${ctx}/bszjzy/list",//请求数据url
			queryParams : {
				accountBodyCard:accountBodyCard,
				beginDate : starTime,
				endDate : endTime,
				sign:sign,
				casemanageId:caseId,
				tradeCount:tradeCount,
				hour:hour,
				keyword:keyword
			},
			height:($(window).height())-($('.box-header').outerHeight(true))-($('#spantitle').outerHeight(true))-35,
			//pagination: true,//允许分页
			rownumbers: true,//行号
			singleSelect: true,//只选择一行
			checkOnSelect: true,
			autoRowHeight : false,//定义是否设置基于该行内容的行高度。设置为 false，则可以提高加载性能。
			fitColumns: true,//真正的自动展开/收缩列的大小，以适应网格的宽度，防止水平滚动。
			pageSize:30,
			pageList:[30,50,100,150,200],
			columns: [[
				{
					field: 'account_BODY',//域值
					title: '交易主体',//内容
					visible: true,//false表示不显示
					width : '10%'
				},
				{
					field: 'account_BODY_CARD',//域值
					title: '交易主体卡号',//内容
					visible: true,//false表示不显示
					width : '10%'
				},
				{
					field: 'account_RIVAL',//域值
					title: '交易对手',//内容
					visible: true,//false表示不显示
					width : '10%'
				},
				{
					field: 'account_RIVAL_CARD',//域值
					title: '交易对手卡号',//内容
					visible: true,//false表示不显示
					width : '10%'
				},
				{
					field: 'rival_COUNT',//域值
					title: '交易次数',//内容
					visible: true,//false表示不显示
					width : '10%',
					formatter: function(value,row,index){ //当前值，当前的row，当前的索引
						let account_RIVAL_CARD='';
						let account_BODY_CARD=row.account_BODY_CARD?row.account_BODY_CARD:'';
						let account_RIVAL_CARD2=row.account_RIVAL_CARD?row.account_RIVAL_CARD:'';
						return "<a href='#' onclick='openDialog(\""+account_BODY_CARD+"\",\""+account_RIVAL_CARD+"\",\""+account_RIVAL_CARD2+"\")'>"+row.rival_COUNT+"</a>";
					}
				},
				{
					field: 'account_RIVAL2',//域值
					title: '伴随转移账户户名',//内容
					visible: true,//false表示不显示
					width : '10%'
				},
				{
					field: 'account_RIVAL_CARD2',//域值
					title: '伴随转移卡号',//内容
					visible: true,//false表示不显示
					width : '10%'
				},
				{
					field: 'count',//域值
					title: '伴随转移次数',//内容
					//sortable: true,//启用排序
					visible: true,//false表示不显示
					width : '10%',
					formatter: function(value,row,index){ //当前值，当前的row，当前的索引
						let account_RIVAL_CARD=row.account_RIVAL_CARD?row.account_RIVAL_CARD:'';
						let account_BODY_CARD=row.account_BODY_CARD?row.account_BODY_CARD:'';
						let account_RIVAL_CARD2=row.account_RIVAL_CARD2?row.account_RIVAL_CARD2:'';
						//let minTime=getMyDate(row.minTime?row.minTime:'');
						//let maxTime=getMyDate(row.maxTime?row.maxTime:'');
						return "<a href='#' onclick='openDialog(\""+account_BODY_CARD+"\",\""+account_RIVAL_CARD+"\",\""+account_RIVAL_CARD2+"\")'>"+row.count+"</a>";
					}
				},
				{
					field: 'sign',//域值
					title: '收付标志',//内容
					visible: true,//false表示不显示
					width : '10%',
					formatter: function(value,row,index){ //当前值，当前的row，当前的索引
						let sign = row.sign;
						if (sign==1){
							return "支出"
						} else{
							return "收入"
						}
					}
				}
			]],
			onLoadSuccess: function (result) {
				var m=[]
				result.rows.map((value,key,arr) =>{
					var s = value.account_BODY+"_"+value.account_BODY_CARD+"_"+value.account_RIVAL+"_"+value.account_RIVAL_CARD;
					var nameArr = []
					m.forEach(function(value,i){
						nameArr.push(value.name)
					})
					var i=nameArr.indexOf(s);
					if(i==-1){
						var obj={name:s,count:value.c}
						m.push(obj)
					}
				})
				//console.log(m)
				var index = 0;
				for (let i = 0; i < m.length; i++) {
					var rowspan=m[i].count;
					$(this).datagrid('mergeCells',{
						index: index,
						field: "account_BODY",
						rowspan: rowspan
					})
					$(this).datagrid('mergeCells',{
						index: index,
						field: "account_BODY_CARD",
						rowspan:rowspan
					})
					$(this).datagrid('mergeCells',{
						index: index,
						field: "account_RIVAL",
						rowspan:rowspan
					})
					$(this).datagrid('mergeCells',{
						index: index,
						field: "account_RIVAL_CARD",
						rowspan:rowspan
					})
					$(this).datagrid('mergeCells',{
						index: index,
						field: "rival_COUNT",
						rowspan:rowspan
					})
					index+=m[i].count
					//console.log(m[i].name,index,rowspan)
				}
			},
			onHeaderContextMenu: function(e, field){
				e.preventDefault();
				if (!cmenu){
					createColumnMenu();
				}
				cmenu.menu('show', {
					left:e.pageX,
					top:e.pageY
				});
			}
		});
        
	}
	function openDialog(account_BODY_CARD,account_RIVAL_CARD,account_RIVAL_CARD2) {
		var param = {
			accountBodyCard:account_BODY_CARD,
		//	accountRival:account_RIVAL,
			accountRivalCard:account_RIVAL_CARD,
			accountRivalCard2:account_RIVAL_CARD2,
		// accountBody:account_BODY,
			sign:$("#sign-info option:selected").val(),
			hour:$("#hour input").val(),
			beginDate : $.trim($("#starTime").val()),
			endDate : $.trim($("#endTime").val()),
			casemanageId:caseId
		}
		var d = top.dialog({
			title : '伴随资金转移详情',
			modal : true,
			url : '${ctx}/bszjzy/bszjzyInitDialog',
			height : 750,
			width : 1500,
			data : param,
			onshow : function () {
			}
		});
		d.show();
		return false;
	}
	function openDiffDayDialog(account_BODY,account_RIVAL,account_RIVAL_CARD,account_BODY_CARD,account_RIVAL_BANK) {
		var param = {
			accountBodyCard:account_BODY_CARD,
			accountRival:account_RIVAL,
			accountRivalCard:account_RIVAL_CARD,
			accountBody:account_BODY,
			accountRivalBank:account_RIVAL_BANK,
			sign:$("#sign-info option:selected").val(),
			hour:$("#hour input").val(),
			beginDate : $.trim($("#starTime").val()),
			endDate : $.trim($("#endTime").val()),
			casemanageId:caseId
		}
		var d = top.dialog({
			title : '伴随资金转移不同交易日期详情',
			modal : true,
			url : '${ctx}/bszjzy/bszjzyDiffDayInitDialog',
			height : 750,
			width : 1500,
			data : param,
			onshow : function () {
			}
		});
		d.show();
		return false;
	}

	function reset(){
		$("#starTime").val('');
		$("#endTime").val('');
	};
 	function exportList(){
	 let starTime = $.trim($("#starTime").val());
	 let endTime = $.trim($("#endTime").val());
	 let sign=$("#sign-info option:selected").val();
	 let tradeCount=$("#tradeCount input").val();
	 let hour=$("#hour input").val();
	 let keyword=$("#keyword").val();
	 let arr = parent.parent._checkedAccount;
	 if (arr&&arr.length>1){
		 toastr.error("请选择一个交易主体卡号","提示信息");
		 return false;
	 }
	 let accountBodyCard=arr[0].split("_")[1];;

	 var xhr = new XMLHttpRequest();
	 var url="${ctx}/bszjzy/downExcel";
	 xhr.open('POST', url, true);
	 xhr.responseType = "blob";  // 返回类型blob
	 // 定义请求完成的处理函数
	 xhr.onload = function () {
		 // 请求完成
		 if (this.status === 200) {
			 var content = this.response;
			 var aTag = document.createElement('a');
			 var blob = new Blob([content]);
			 var headerName = xhr.getResponseHeader("Content-disposition");
			 var fileName = decodeURIComponent(headerName).substring(20);
			 aTag.download = fileName;
			 aTag.href = URL.createObjectURL(blob);
			 aTag.click();
			 URL.revokeObjectURL(blob);
		 }
	 };
	 // 发送ajax请求
	 var formdata=new FormData();
	 formdata.append("casemanageId",caseId);
	 formdata.append("sign",sign);
	 formdata.append("hour",hour);
	 formdata.append("accountBodyCard",accountBodyCard);
	 formdata.append("tradeCount",tradeCount);
	 formdata.append("beginDate",starTime);
	 formdata.append("endDate",endTime);
	 formdata.append("keyword",keyword);
	 xhr.send(formdata);
 };

    /*列显示下拉框*/
    var cmenu;
    function createColumnMenu(){
        cmenu = $('<div/>').appendTo('body');
        cmenu.menu({
            onClick: function(item){
                if (item.iconCls == 'icon-ok'){
                    $('#dg').datagrid('hideColumn', item.name);
                    cmenu.menu('setIcon', {
                        target: item.target,
                        iconCls: 'icon-empty'
                    });
                } else {
                    $('#dg').datagrid('showColumn', item.name);
                    cmenu.menu('setIcon', {
                        target: item.target,
                        iconCls: 'icon-ok'
                    });
                }
            }
        });
        var fields = $('#dg').datagrid('getColumnFields');
        for(var i=0; i<fields.length; i++){
            var field = fields[i];
            var col = $('#dg').datagrid('getColumnOption', field);
            cmenu.menu('appendItem', {
                text: col.title,
                name: field,
                iconCls: 'icon-ok'
            });
        }
    };
</script>
<style>
	input.zjzytime {
		width: 55px!important;
		height: 30px!important;
		text-align: center;
		font-size: 12PX;
	}
	select.zjzysign {
		height: 30px;
		width: 55px;
		border-color: #e4e4e4;
		font-size: 12PX;
	}
	label.control-label.refsh {
		margin-left: -19px;
	}
	.box-body{
		padding-left: 5px;
		padding-right: 0;
	}
	.content{
		padding-top: 0;
		padding-bottom: 0;
	}
	content-wrapper{
		padding-top: 0;
	}
	input#starTime{
		width: 120px;
		height: 30px;
		border-radius: 0;
	}
	input#endTime{
		width: 120px;
		height: 30px;
		border-radius: 0;
	}
	input.btn.btn-primary {
		width: 70px;
		height: 30px;
		line-height: 12px;
	}
	input.btn.btn-default{
		width: 70px;
		height: 30px;
		line-height: 12px;
	}
	input.btn.btn-primary.daobtn{
		background-color: #23B7E5;
		border-color: #23B7E5
	}
	.camanage-list{
		border-radius: 0 4px 4px 0;
	}
	.casemanage-switchtip {
		display: block;
		position: fixed;
		right: -10px;
		top: 10px;
	}
	.content-wrapper {
		padding:10px;
	}
	.casemanage-switch {
		margin-right: 50px!important;
	}
	.box-header .row label{
		margin-right: 5px;
		color: #6f7689;
		font-size: 13px;
		font-weight: 400;
	}
	.badge{
		background-color: #f7051f;
	}
	.form-control{
		font-size: 12PX;
	}
	.box-header .form-group{
		margin-right: 20px;
	}
	label.control-label.hidden-xs.form_z {
		margin-right: 6px;
		margin-left: -6px;
	}
	.bill-buttonarea .btn{
		margin-right: 12px;
		width: 70px;
	}
	.btn-primary:active:focus{
		background-color: #4695ed;
		border-color: #4695ed;
	}
	.casemanage-switch .casemanage-zhexiantu.active {
		background-color: #4695ed;
	}
	.casemanage-switch .casemanage-zhexiantu {
		background-color: #f2f6f9;
		float: left;
		width: 50px;
		height: 35px;
		display: block;
		cursor: pointer;
		border-top-left-radius: 5px;
		border-bottom-left-radius: 5px;
		line-height: 35px;
		text-align: center;
	}
	#font_zhexian{
		color: #C1C2C3;
		font-size: 18px;
	}
	#font_zhexian.active{
		color: #F4F9FE;
	}
	.box{
		padding: 0;
		margin-bottom: 0;
	}
	.box-body .title{
		font-size:14px;
		font-weight:800;
		line-height:30px;
	}
	.box-body{
		padding-bottom: 0;
	}
	.box-body .casemanage-switch{
		margin:0;
	}
	.btn-primary{
		background-color:#4695ed;
		border-color:#4695ed;
	}
	.btn-primary:hover, .btn-primary:active, .btn-primary.hover{
		background: #61a8f5;
		border-color: #61a8f5;
	}
	.btn-primary.focus, .btn-primary:focus{
		background-color:#4695ed;
		border-color:#4695ed;
	}
	.form-control{
		border-radius:4px;
		border-color: #e4e4e4;
	}
	.input-group .form-control:first-child{
		border-top-right-radius:4px;
		border-bottom-right-radius: 4px;
	}
	.form-control:focus{
		border-color:#4695ed;
	}
	.form-control:hover{
		border-color:#4695ed;
	}
	#hour input , #tradeCount input {
		width: 120px;
	}
</style>
</body>
</html>